package gamesrv.server.impl;

import gamesrv.api.GameHandle;
import gamesrv.api.GameNotReadyException;
import gamesrv.api.GameStatus;
import gamesrv.api.IllegalMoveException;
import gamesrv.api.NotMyMoveException;

public class GameHandleImpl implements GameHandle {
	GameContainer game;	
	String userName;
	int userNumber;
	
	public void setGame(GameContainer game,int userNumber)
	{
		this.userNumber = userNumber;
		this.game = game;
	}
	
	
	public GameHandleImpl(String userName)
	{
		this.userName = userName;
	}
	
	
	public String getUserName() { return userName;}
	
	
	
	public String getUserName(int number) {
		// TODO Auto-generated method stub
		return null;
	}


	
	public int getMyNumber() {		
		return userNumber;
	}
	
	
	public int getUserCount()
	{
		return game.getUserCount();
	}
	
	
	public GameStatus getStatus() {
		if (game == null)
			return GameStatus.Waiting;
		if (game.isFinished())
			return GameStatus.Finished;
		if (game.nextMove() == getMyNumber())
			return GameStatus.ReadyForMove;
		else
			return GameStatus.Waiting;				
	}
	
	
	public void move(String[] move) throws GameNotReadyException, NotMyMoveException,IllegalMoveException {				
		game.makeMove(this,move);					
	}
	
	public String getScore()
	{
		return game.getScore();		
	}

	
	public String[][] getSituation()
	{
		return game.getSituation();
	}


	
	
	

	


	
	public int getNextUser() {		
		return game.nextMove();
	}
	
	
	

	

}
